<template>
  <div class="login">
     <div class="box">
        <!-- form表单 -->
        <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
            <el-form-item label="用户名" prop="username">
                <el-input v-model="ruleForm.username"></el-input>
            </el-form-item>
             <el-form-item label="密码" prop="password">
                <el-input v-model="ruleForm.password"></el-input>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="submitForm('ruleForm')">立即创建</el-button>
                <el-button @click="resetForm('ruleForm')">重置</el-button>
            </el-form-item>
        </el-form>
     </div>
  </div>
</template>

<script>
// @ is an alias to /src
// import HelloWorld from '@/components/HelloWorld.vue'
import {loginApi} from '@/utils/api.js'
export default {
  name: 'HomeView',
  data() {
    return {
        ruleForm:{
            username:'',
            password:''
        },
        rules:{
           username: [
            { required: true, message: '请输入活动名称', trigger: 'blur' },
            { pattern:/^[a-zA-Z0-9]+$/i, message: '用户名是数字或者字母', trigger: 'blur' }
          ],
           password: [
            { required: true, message: '请填写活动形式', trigger: 'blur' }
          ]
        }
    }
  },
  methods: {
   submitForm(formName){
    this.$refs[formName].validate((valid) => {
          if (valid) {
             loginApi(this.ruleForm)
             this.$router.push('/')
          } else {
           
            return false;
          }
});
   }
  },
  components: {
    // HelloWorld
  }
}
</script>
<style lang="scss" scoped>
.login{
    width:100%;
    height: 100vh;
    background: skyblue;
    display: flex;
    align-items: center;
    justify-content: center;
    .box{
        width:400px;
        height: 260px;
        background: #ffff;
        border-radius: 10px;
        padding: 40px 30px;
    }
}
</style>

